Skip to content

Unit tests middleware cicd - #130

Merged
NiveditJain merged 17 commits into
FailproofAI:mainfrom
namidanam:unit-tests-middleware-cicd
Aug 2, 2025
Merged

Unit tests middleware cicd#130
NiveditJain merged 17 commits into
FailproofAI:mainfrom
namidanam:unit-tests-middleware-cicd

Conversation

@namidanam

Copy link
Copy Markdown
Contributor

This PR separates unit tests for RequestIdMiddleware and UnhandledExceptionsMiddleware into individual files for improved clarity and maintainability.

Adds/updates test files in api-server/tests/.

Adds pytest to dev dependencies.

Updates the CI workflow to automatically install dependencies with uv and run all tests on every commit and pull request.

@coderabbitai

coderabbitai Bot commented Aug 2, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

  • Chores

    • Added automated testing workflow for continuous integration, including environment setup, test execution, and coverage reporting.
    • Updated development dependencies to include testing and coverage tools.
  • Tests

    • Introduced tests for request ID middleware to verify correct handling of request ID headers.
    • Added tests for unhandled exceptions middleware to ensure proper error responses and normal request handling.

Walkthrough

A continuous integration workflow was introduced for automated testing of a Python API server. The pytest, httpx, and pytest-cov dependencies were added to the project's configuration. Two new test modules were created to verify the behavior of the RequestIdMiddleware and UnhandledExceptionsMiddleware in FastAPI, each providing fixtures and multiple test cases.

Changes

Cohort / File(s) Change Summary
CI Workflow Introduction
.github/workflows/ci.yml
Added a GitHub Actions workflow to automate testing on pushes and pull requests to main. The workflow sets up Python 3.12, installs dependencies with uv (including caching), runs tests using pytest with coverage reporting, and uploads coverage data to Codecov. A Redis service container with health checks is included.
Dependency Update
api-server/pyproject.toml
Adjusted indentation of closing brackets in [project] and [dependency-groups]. Added pytest>=8.0.0, httpx>=0.27.0, and pytest-cov>=5.0.0 to the dev dependency group.
Request ID Middleware Tests
api-server/tests/test_request_id_middleware.py
Added a test module with a FastAPI app fixture applying RequestIdMiddleware. Implemented tests to verify UUID generation when missing, preservation of valid UUIDs, and replacement of invalid UUIDs in request ID headers. Each test asserts status code, header presence, and response body correctness.
Unhandled Exceptions Middleware Tests
api-server/tests/test_unhandled_exceptions_middleware.py
Added a test module with a FastAPI app fixture applying UnhandledExceptionsMiddleware. Defined endpoints that raise RuntimeError, ValueError, KeyError, and a healthy endpoint. Added tests verifying that exceptions produce 500 status with appropriate JSON error responses and that normal requests return expected success responses.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub
    participant CI Workflow
    participant Python Env
    participant Test Runner
    participant Redis Service
    participant Codecov

    Developer->>GitHub: Push or PR to main
    GitHub->>CI Workflow: Trigger workflow
    CI Workflow->>Python Env: Set up Python 3.12
    CI Workflow->>Redis Service: Start Redis container with health checks
    CI Workflow->>Python Env: Install dependencies with uv (cache enabled)
    CI Workflow->>Test Runner: Run pytest with coverage
    Test Runner-->>CI Workflow: Return test results and coverage reports
    CI Workflow->>Codecov: Upload coverage reports (fail-on-error)
    CI Workflow-->>GitHub: Update status
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇
In the garden of code, new workflows bloom,
Tests for middleware chase away gloom.
With pytest in tow and CI in the sky,
Each push and pull gets a watchful eye.
Now errors and headers are caught with delight—
The rabbits rejoice, for the future is bright!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c6031b and d4a6a1d.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml (1 hunks)
  • api-server/pyproject.toml (1 hunks)
  • api-server/tests/test_unhandled_exceptions_middleware.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: the exospherehost project requires python versions > 3.12 for the ci workflow, meaning python 3.13 o...
Learnt from: NiveditJain
PR: exospherehost/exospherehost#130
File: .github/workflows/ci.yml:22-22
Timestamp: 2025-08-02T12:43:35.075Z
Learning: The exospherehost project requires Python versions > 3.12 for the CI workflow, meaning Python 3.13 or higher should be used despite potential stability concerns with pre-release versions.

Applied to files:

  • .github/workflows/ci.yml
🪛 YAMLlint (1.37.1)
.github/workflows/ci.yml

[warning] 3-3: truthy value should be one of [false, true]

(truthy)


[error] 55-55: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (4)
.github/workflows/ci.yml (2)

1-55: Well-structured CI workflow with proper coverage integration.

The workflow effectively addresses the CI requirements with Python 3.12, Redis service setup, dependency caching, and Codecov integration. The configuration aligns with the project's testing needs.


3-7: Fix YAML formatting issues flagged by static analysis.

The YAML has a truthy value warning and missing newline at end of file.

Apply this diff to address the static analysis warnings:

 on:
   push:
-    branches: [main]
+    branches: ["main"]
   pull_request:
-    branches: [main]
+    branches: ["main"]

Also add a newline at the end of the file (line 55).

Likely an incorrect or invalid review comment.

api-server/tests/test_unhandled_exceptions_middleware.py (2)

7-29: Excellent test coverage with multiple exception types.

The test structure properly covers different exception scenarios (RuntimeError, ValueError, KeyError) and includes a healthy endpoint test. The fixture setup is clean and follows good testing practices.


31-34: Good use of constant for expected error response.

Using ERROR_RESPONSE constant for exact matching is appropriate given the fixed error message format in the middleware implementation.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bedae6d and 18902ab.

⛔ Files ignored due to path filters (1)
  • api-server/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • .github/workflows/ci.yml (1 hunks)
  • api-server/pyproject.toml (1 hunks)
  • api-server/tests/test_request_id_middleware.py (1 hunks)
  • api-server/tests/test_unhandled_exceptions_middleware.py (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/ci.yml

15-15: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


18-18: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 YAMLlint (1.37.1)
.github/workflows/ci.yml

[warning] 3-3: truthy value should be one of [false, true]

(truthy)


[error] 20-20: trailing spaces

(trailing-spaces)

🔇 Additional comments (4)
.github/workflows/ci.yml (2)

20-20: Verify Python 3.13 compatibility across dependencies

We ran a classifier check against PyPI and found that while most packages declare support for Python 3.13, the following do not list it explicitly:

• beanie
• docker-image-py
• email-validator
• redis[hiredis]

Please:

  • Run the full test suite under Python 3.13 in CI (e.g. add python-version: ['3.11', '3.13'] to the matrix).
  • Manually install and smoke-test the four packages above, or upgrade to versions that advertise 3.13 support.
  • Confirm that no runtime issues arise (import errors, deprecations, etc.).

Once verified (or packages updated), we can be confident in promoting Python 3.13 in CI.


3-7: Fix YAML formatting issue.

The on keyword should use boolean values instead of truthy values.

Apply this diff:

 on:
   push:
-    branches: [main]
+    branches: ["main"]
   pull_request:
-    branches: [main]
+    branches: ["main"]

Likely an incorrect or invalid review comment.

api-server/tests/test_unhandled_exceptions_middleware.py (1)

1-35: LGTM! Well-structured middleware tests.

The test implementation follows good practices with proper fixture setup, clear test separation, and coverage of both success and failure scenarios.

api-server/tests/test_request_id_middleware.py (1)

1-38: Excellent test coverage for RequestIdMiddleware!

The test implementation comprehensively covers the three main scenarios for request ID handling with proper UUID validation and clear assertions.

Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread api-server/pyproject.toml Outdated
Comment thread api-server/tests/test_request_id_middleware.py Outdated
Comment on lines +32 to +37
def test_replaces_invalid_id(client):
resp = client.get("/test", headers={"x-exosphere-request-id": "bad-id"})
assert resp.status_code == 200
new_id = resp.headers["x-exosphere-request-id"]
assert new_id != "bad-id"
uuid.UUID(new_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider testing additional edge cases.

The current tests cover the main scenarios well. Consider adding tests for edge cases like empty strings, whitespace-only strings, or extremely long invalid IDs.

You could add additional test cases:

def test_replaces_empty_id(client):
    resp = client.get("/test", headers={"x-exosphere-request-id": ""})
    assert resp.status_code == 200
    new_id = resp.headers["x-exosphere-request-id"]
    assert new_id != ""
    uuid.UUID(new_id)

def test_replaces_whitespace_id(client):
    resp = client.get("/test", headers={"x-exosphere-request-id": "   "})
    assert resp.status_code == 200
    new_id = resp.headers["x-exosphere-request-id"]
    assert new_id.strip() != ""
    uuid.UUID(new_id)
🤖 Prompt for AI Agents
In api-server/tests/test_request_id_middleware.py around lines 32 to 37, the
tests currently check for invalid request IDs but do not cover edge cases like
empty strings, whitespace-only strings, or very long invalid IDs. Add new test
functions that send requests with these edge case headers, verify the response
status is 200, confirm the returned request ID is different from the invalid
input, and validate that the new ID is a proper UUID.

Comment thread api-server/tests/test_request_id_middleware.py Outdated
Comment thread api-server/tests/test_unhandled_exceptions_middleware.py
Comment thread api-server/tests/test_unhandled_exceptions_middleware.py Outdated
namidanam and others added 2 commits August 2, 2025 13:17
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18902ab and 80ba9f9.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/ci.yml (1)

18-21: Re-evaluate hard-coding Python 3.13
Python 3.13 is still in pre-release; GitHub runners may not yet provide a stable binary and actions/setup-python@v5 will silently fall back to the latest stable (currently 3.12). If the codebase truly depends on 3.13 features, the workflow could fail unpredictably in the near term. Consider one of:

-          python-version: '3.13'
+          python-version: '3.12'  # or the lowest supported version
+#         python-version-file: '.python-version'   # keep in sync with repo config

or introduce a matrix to cover the supported range:

strategy:
  matrix:
    python-version: ['3.11', '3.12']

Comment thread .github/workflows/ci.yml
Comment thread .github/workflows/ci.yml Outdated
@NiveditJain

NiveditJain commented Aug 2, 2025 via email

Copy link
Copy Markdown
Member

@namidanam

Copy link
Copy Markdown
Contributor Author

Closed the other PR

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
api-server/pyproject.toml (1)

23-33: Broken table & unmatched bracket – [dependency-groups] declared twice

Lines 23-28 introduce a second [dependency-groups] table and leave a stray closing ] (Line 28).
This produces both a duplicate table error and invalid TOML syntax.

Consolidate the dev group into the single table that already starts at Line 30:

-[dependency-groups]
-dev = [
-    "ruff>=0.12.2",
-    "pytest>=8.0.0",
-]
-]
-
-[dependency-groups]
-dev = [
-    "ruff>=0.12.2",
-]
+[dependency-groups]
+dev = [
+    "ruff>=0.12.2",
+    "pytest>=8.0.0",
+]

This removes the duplicate table, fixes the bracket imbalance, and keeps pytest in the correct dev group (per the earlier review).
After this change the file should parse and the CI workflow will succeed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80ba9f9 and a0fa269.

📒 Files selected for processing (1)
  • api-server/pyproject.toml (1 hunks)

Comment thread api-server/pyproject.toml Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
api-server/pyproject.toml (1)

27-30: Duplicate [dependency-groups] block – remove the second instance

Lines 27-30 re-declare the same table, causing a duplicate-key error. Drop the redundant block or merge any unique entries into the first one.

-[dependency-groups]
-dev = [
-    "ruff>=0.12.2",
-]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0fa269 and f596ced.

📒 Files selected for processing (1)
  • api-server/pyproject.toml (1 hunks)

Comment thread api-server/pyproject.toml Outdated
namidanam and others added 2 commits August 2, 2025 15:03
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/ci.yml (1)

31-34: Surface test results & coverage artefacts for better PR feedback
Pytest output goes to stdout only, so GitHub can’t annotate failures or track coverage trends.

-      - name: Run tests with pytest
+      - name: Run tests with pytest & publish report
         working-directory: api-server
         run: |
-          uv run pytest --maxfail=1 --disable-warnings -v
+          uv run pytest \
+            --maxfail=1 \
+            --disable-warnings \
+            --junitxml=pytest-report.xml \
+            -v
+
+      - name: Upload test report
+        if: always()
+        uses: actions/upload-artifact@v4
+        with:
+          name: pytest-report
+          path: api-server/pytest-report.xml
+
+      - name: Measure coverage
+        working-directory: api-server
+        run: |
+          uv run coverage run -m pytest
+          uv run coverage xml -o coverage.xml
+
+      - name: Upload coverage report
+        if: always()
+        uses: actions/upload-artifact@v4
+        with:
+          name: coverage
+          path: api-server/coverage.xml

This lets the UI highlight failing lines and opens the door to coverage-gating later.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aac48d and 55f1ec1.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/ci.yml (1)

22-26: Nice touch—dependency caching enabled
Enabling cache: true on astral-sh/setup-uv makes repeated runs significantly faster. Good improvement.

Comment thread .github/workflows/ci.yml Outdated
namidanam and others added 2 commits August 2, 2025 15:30
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
api-server/pyproject.toml (1)

6-6: requires-python is incompatible with the CI matrix

requires-python = ">=3.12" blocks installation on Python 3.11, yet the workflow runs tests on 3.11. Either widen the requirement (e.g., ">=3.11") or drop 3.11 from the matrix, otherwise dependency resolution will fail in CI and for any users on 3.11.

♻️ Duplicate comments (2)
api-server/pyproject.toml (1)

18-18: Trailing comma on the same line as the closing bracket is legal but jarring

"redis[hiredis]>=6.0.0",] is valid TOML, yet it’s an uncommon style that may trip linters or future contributors. Consider moving ] to its own line for consistency with the rest of the array.

-    "redis[hiredis]>=6.0.0",]
+    "redis[hiredis]>=6.0.0",
+]
.github/workflows/ci.yml (1)

34-37: Consider emitting JUnit & coverage artefacts for richer feedback

Publishing a JUnit XML and coverage report lets GitHub annotate failures inline and enforces test coverage thresholds.

-          uv run pytest --maxfail=1 --disable-warnings -v
+          uv run pytest \
+            --maxfail=1 --disable-warnings -v \
+            --junitxml=pytest-report.xml \
+            --cov=api_server --cov-report=xml

You can then upload the reports with actions/upload-artifact or actions/upload-test-results.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55f1ec1 and e46b6d3.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml (1 hunks)
  • api-server/pyproject.toml (1 hunks)
🔇 Additional comments (2)
api-server/pyproject.toml (1)

23-24: Good call adding test-only tooling to the dev group

Placing pytest and httpx under dev cleanly separates runtime from development dependencies.

.github/workflows/ci.yml (1)

25-29: Nice! Dependency caching is enabled

Using cache: true for setup-uv will materially speed up repeated runs.

Comment thread .github/workflows/ci.yml Outdated
namidanam and others added 3 commits August 2, 2025 15:39
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
api-server/tests/test_unhandled_exceptions_middleware.py (1)

8-9: Consider testing different exception types.

The test only covers RuntimeError. Consider adding tests for other exception types to ensure comprehensive middleware behavior validation.

api-server/tests/test_request_id_middleware.py (1)

34-41: Consider testing additional edge cases.

The current tests cover the main scenarios well. Consider adding tests for edge cases like empty strings, whitespace-only strings, or extremely long invalid IDs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e46b6d3 and 624d2ca.

📒 Files selected for processing (2)
  • api-server/tests/test_request_id_middleware.py (1 hunks)
  • api-server/tests/test_unhandled_exceptions_middleware.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
api-server/tests/test_unhandled_exceptions_middleware.py (2)
api-server/tests/test_request_id_middleware.py (1)
  • client (13-17)
api-server/app/middlewares/unhandled_exceptions_middleware.py (1)
  • UnhandledExceptionsMiddleware (10-30)
🔇 Additional comments (6)
api-server/tests/test_unhandled_exceptions_middleware.py (2)

15-21: LGTM: Clean test fixture setup.

The test fixture properly sets up a FastAPI app with the middleware and defines appropriate test routes for both error and success scenarios.


30-33: LGTM: Normal request test is appropriate.

The test correctly verifies that normal requests pass through the middleware unaffected.

api-server/tests/test_request_id_middleware.py (4)

8-10: LGTM: Simple test endpoint.

The minimal endpoint is appropriate for testing middleware functionality without unnecessary complexity.


12-17: LGTM: Well-structured test fixture.

The fixture properly sets up a FastAPI app with only the RequestIdMiddleware, providing good isolation for testing.


19-26: LGTM: Explicit UUID validation implemented.

The test correctly validates UUID generation and uses explicit assertion as suggested in previous reviews.


28-32: LGTM: Valid ID preservation test.

The test appropriately verifies that valid UUIDs are preserved by the middleware.

Comment thread api-server/tests/test_unhandled_exceptions_middleware.py Outdated

@NiveditJain NiveditJain left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@namidanam please fix the review comments, also along with to merge this PR you will need to:

  • Fix failing test in actions (you will need to add Redis to actions pipeline and connect it to main app for tests)
  • Connect codecov
  • Fix comments

Comment thread .github/workflows/ci.yml Outdated
with:
# Prefer released versions or test a matrix of supported ones
python-version: |
3.11

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid comment by @coderabbitai, this should be only for python versions > 3.12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NiveditJain, understood! I'll update the CI workflow to use Python versions > 3.12. Here's the corrected configuration:

- name: Set up Python
  uses: actions/setup-python@v5
  with:
    python-version: |
      3.13

Or if you want to test against multiple versions > 3.12:

- name: Set up Python
  uses: actions/setup-python@v5
  with:
    python-version: |
      3.13
      3.14-dev

Note that Python 3.13 is currently in release candidate stage, so there might be occasional stability issues with the GitHub runners, but if your project specifically requires features from Python 3.13+, this is the right approach.


✏️ Learnings added
Learnt from: NiveditJain
PR: exospherehost/exospherehost#130
File: .github/workflows/ci.yml:22-22
Timestamp: 2025-08-02T12:43:35.052Z
Learning: The exospherehost project requires Python versions > 3.12 for the CI workflow, meaning Python 3.13 or higher should be used despite potential stability concerns with pre-release versions.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment thread .github/workflows/ci.yml Outdated
Comment thread api-server/tests/test_unhandled_exceptions_middleware.py
Comment thread api-server/pyproject.toml Outdated
"uvicorn>=0.35.0",
"redis[hiredis]>=6.0.0"
]
"redis[hiredis]>=6.0.0",]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

    "redis[hiredis]>=6.0.0"
]

Comment thread api-server/pyproject.toml Outdated
Comment thread api-server/tests/test_unhandled_exceptions_middleware.py Outdated
@NiveditJain
NiveditJain self-requested a review August 2, 2025 12:43

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

♻️ Duplicate comments (1)
api-server/pyproject.toml (1)

18-18: Bracket-on-same-line hurts readability

Closing the dependencies array on the same line as the last element is valid TOML, but it’s inconsistent with the multi-line style used above and makes future diffs noisy.

-    "redis[hiredis]>=6.0.0"]
+    "redis[hiredis]>=6.0.0",
+]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77d09e7 and 4c6031b.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml (1 hunks)
  • api-server/pyproject.toml (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: the exospherehost project requires python versions > 3.12 for the ci workflow, meaning python 3.13 o...
Learnt from: NiveditJain
PR: exospherehost/exospherehost#130
File: .github/workflows/ci.yml:22-22
Timestamp: 2025-08-02T12:43:35.052Z
Learning: The exospherehost project requires Python versions > 3.12 for the CI workflow, meaning Python 3.13 or higher should be used despite potential stability concerns with pre-release versions.

Applied to files:

  • .github/workflows/ci.yml
🪛 actionlint (1.7.7)
.github/workflows/ci.yml

48-48: "steps" section is missing in job "uses"

(syntax-check)


48-48: "runs-on" section is missing in job "uses"

(syntax-check)


48-48: "uses" job is scalar node but mapping node is expected

(syntax-check)


49-49: "steps" section is missing in job "with"

(syntax-check)


49-49: "runs-on" section is missing in job "with"

(syntax-check)


50-50: unexpected key "token" for "job" section. expected one of "concurrency", "container", "continue-on-error", "defaults", "env", "environment", "if", "name", "needs", "outputs", "permissions", "runs-on", "secrets", "services", "steps", "strategy", "timeout-minutes", "uses", "with"

(syntax-check)


51-51: unexpected key "slug" for "job" section. expected one of "concurrency", "container", "continue-on-error", "defaults", "env", "environment", "if", "name", "needs", "outputs", "permissions", "runs-on", "secrets", "services", "steps", "strategy", "timeout-minutes", "uses", "with"

(syntax-check)


52-52: unexpected key "files" for "job" section. expected one of "concurrency", "container", "continue-on-error", "defaults", "env", "environment", "if", "name", "needs", "outputs", "permissions", "runs-on", "secrets", "services", "steps", "strategy", "timeout-minutes", "uses", "with"

(syntax-check)


53-53: unexpected key "flags" for "job" section. expected one of "concurrency", "container", "continue-on-error", "defaults", "env", "environment", "if", "name", "needs", "outputs", "permissions", "runs-on", "secrets", "services", "steps", "strategy", "timeout-minutes", "uses", "with"

(syntax-check)


55-55: unexpected key "fail_ci_if_error" for "job" section. expected one of "concurrency", "container", "continue-on-error", "defaults", "env", "environment", "if", "name", "needs", "outputs", "permissions", "runs-on", "secrets", "services", "steps", "strategy", "timeout-minutes", "uses", "with"

(syntax-check)

🪛 YAMLlint (1.37.1)
.github/workflows/ci.yml

[warning] 3-3: truthy value should be one of [false, true]

(truthy)


[error] 12-12: trailing spaces

(trailing-spaces)


[error] 31-31: trailing spaces

(trailing-spaces)


[error] 32-32: trailing spaces

(trailing-spaces)


[error] 56-56: too many blank lines (1 > 0)

(empty-lines)

Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread api-server/pyproject.toml Outdated
@namidanam

Copy link
Copy Markdown
Contributor Author

resolved the mentioned issues, please review if any more changes are to be made

@codecov

codecov Bot commented Aug 2, 2025

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@NiveditJain
NiveditJain merged commit 267ab06 into FailproofAI:main Aug 2, 2025
5 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants